package com.imut.lagain.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    
    @Value("${file.upload.path}")
    private String uploadPath;
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置通用的文件资源访问
        registry.addResourceHandler("/files/**")
                .addResourceLocations("file:" + uploadPath + "/");
        
        // 配置图片资源访问 - 修复路径映射
        registry.addResourceHandler("/files/images/**")
                .addResourceLocations("file:" + uploadPath + "/images/");
        
        // 配置音频资源访问
        registry.addResourceHandler("/files/audios/**")
                .addResourceLocations("file:" + uploadPath + "/audios/");
        
        // 配置语音资源访问
        registry.addResourceHandler("/files/voices/**")
                .addResourceLocations("file:" + uploadPath + "/voices/");
    }
}